// DriveNotes. Copyright (c) 2011, Andrei Senchuk. All rights reserved.
package net.taviscaron.drivenotes.server.service;

import net.taviscaron.drivenotes.server.model.dao.UserDAO;
import net.taviscaron.drivenotes.server.util.EntityUtils;
import net.taviscaron.drivenotes.shared.model.entity.User;
import net.taviscaron.drivenotes.shared.service.LoginService;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.transaction.annotation.Transactional;

/**
 * Login service
 * @author Andrei Senchuk
 */
public class LoginServiceImpl implements LoginService {
    private UserDAO userDAO;

    @Required
    public void setUserDAO(UserDAO userDAO) {
        this.userDAO = userDAO;
    }

    @Transactional
    public User findUserByCredentials(String username, String password) {
        User user = userDAO.findByCredentials(username, password);
        return EntityUtils.createUserValueObject(user);
    }

    @Transactional
    public User findById(Long userId) {
        User user = userDAO.findById(userId);
        return EntityUtils.createUserValueObject(user);
    }
}
